Y8 Basics of Python turtle
Welcome to the interactive get drawing with python turtle page. This page should guide you through starting python and drawing using the turtle module.
Perform the actions in red.
Write the codes shown in green into your code editor and run it.
== First read the information under the form ==
When you are ready Enter your name and press START:
The easiest option when in CS lessons is to use the IDLE editor installed on the college computers
To have python installed on your computer use: python.org downloads
Make sure the website detects your correct operating system before installing
First turtle program
Python is a text based programming language
If you are using the IDLE open the editor: select File->New File
If you are using repl choose "Create" and select "Python (with Turtle)"
In the code editor window enter the lines:
from turtle import *
forward(100)
Test it! If you are using the IDLE select Run->Run Module the shortcut key is F5. Save to Onedrive if possible and name your program test1 or similar. If you are using replit just press Run
Othwerwise work out how to save and run the code on the editor you are using
Pen settings
The instruction forward(100) calls the forward() function with 100 as the argument (or parameter):
Before the forward instruction insert the lines:
color("blue")
pensize(8)
Press F5 to test your program
The picture shows code for a thick green line
Can you change the code to get a thin red line?
Error messages
The code executes in the shell window or console
If there is a mistake in the code a red error message will often be printed.
Append (add to the end) these three lines:
back(50)
right(90)
down(50)
In this code there is a common error people make. The down() function should not have a argument in the brackets. It does not move the pen downwards on the drawing canvas.
down() does the opposite of the up(). The up() fucntion lifts the pen away from the canvas so the pen can move without drawing.
The down() function places the pen back onto the canvas to draw.
Three of these statements are correct ...
Extended code sequence
Commands can be added to the program and will be performed in order
Try this program:
from turtle import *
color("ForestGreen")
pensize(8)
left(90)
forward(50)
up()
right(90)
forward(80)
right(90)
down()
forward(50)
back(50)
color("DarkOliveGreen")
right(90)
back(10)
forward(100)
hideturtle()
Iterative code sequence
Commands can be placed inside a repeating for loop to be executed more than once
Create a new file and make the program shown:
The program makes use of repetition.
This is also called iteration as you can program it
so that each repitition does something different.
Change some of the numbers that are sent as arguments
to the functions and run the program to see the effect.
Well done you have completed the Python turtle introduction
Have a look at the python art section on the Y8 index page "samples to try" or browse the internet for python turtle examples